import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.path import Path

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
plt.rcParams['toolbar'] = 'toolmanager'
# 有中文出现的情况，需要u'内容'

# 画图

data2 = pd.read_csv('data/data.csv', sep=',')
# 划区域
# https://matplotlib.org/stable/gallery/shapes_and_collections/compound_path.html#sphx-glr-gallery-shapes-and-collections-compound-path-py
# 在图中圈起来的范围, 最后一个点要回来
vertices = [(30, 420), (30, 440), (50, 440), (50, 420), (30, 420)]
codes = [Path.MOVETO] + [Path.LINETO] * (len(vertices) - 2) + [Path.CLOSEPOLY]
series_scope = Path(vertices, codes)
pathpatch = PathPatch(series_scope, facecolor='none', edgecolor='red')
f, ax = plt.subplots(1, 2)

ax[1].imshow(data2[420:440][data2.columns[30:50]], cmap="gray")
ax[1].set_title('想要查找的图')

ax[0].imshow(data2, cmap="gray")
ax[0].set_title("整体图")
ax[0].add_patch(pathpatch)
ax[0].autoscale_view()

# 画箭头
# https: // blog.csdn.net / qq_21478261 / article / details / 108290310
ax[0].annotate('',
               xy=(-1, 10), xycoords=ax[1].transData,
               xytext=(30, 420), textcoords=ax[0].transData,
               ha="center", va="center",
               # bbox={'facecolor': '#74C476', "boxstyle": "round"},
               arrowprops=dict(facecolor='#74C476', alpha=0.6, arrowstyle='-|>', linewidth=2, color='r'),
               )
plt.show()
